Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lift dependencies to the workspace (Part 1) #2070

Merged
merged 6 commits into from
Feb 12, 2024
Merged

Lift dependencies to the workspace (Part 1) #2070

merged 6 commits into from
Feb 12, 2024

Conversation

ggwpez
Copy link
Member

@ggwpez ggwpez commented Oct 27, 2023

Changes (partial #994):

  • Set log to 0.4.20 everywhere
  • Lift log to the workspace

Starting with a simpler one after seeing #2065 from @jsdw.
This sets the default-features to false in the root and then overwrites that in each create to its original value. This is necessary since otherwise the default features are additive and its impossible to disable them in the crate again once they are enabled in the workspace.

I am using a tool to do this, so its mostly a test to see that it works as expected.

@ggwpez ggwpez added the R0-silent Changes should not be mentioned in any release notes label Oct 27, 2023
@ggwpez ggwpez marked this pull request as ready for review October 27, 2023 21:27
@ggwpez ggwpez requested review from a team October 27, 2023 21:27
@ggwpez ggwpez requested a review from a team October 27, 2023 21:27
@ggwpez ggwpez requested review from koute and a team as code owners October 27, 2023 21:27
@paritytech-ci paritytech-ci requested a review from a team October 27, 2023 21:28
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not disable the default features in the workspace. IMO this "feels" weird.

And BTW, the wasm-builder currently not supports workspace deps.

Cargo.toml Outdated
@@ -4,6 +4,9 @@ edition = "2021"
repository = "https://github.com/paritytech/polkadot-sdk.git"
license = "GPL-3.0-only"

[workspace.dependencies]
log = { version = "^0.4.20", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log = { version = "^0.4.20", default-features = false }
log = "0.4.20"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that if the default-features are not disabled in the workspace, then they cannot be disabled lateron in the crates, since features are additive.
So AFAIK it is best practice to disable them at the workspace and then re-enable at the crate level - if desired. It is explained here rust-lang/cargo#11329

@@ -10,7 +10,7 @@ async-trait = "0.1.73"
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ] }
dyn-clone = "1.0.12"
futures = "0.3.28"
log = "0.4.20"
log = { workspace = true, default-features = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log = { workspace = true, default-features = true }
log = { workspace = true }

This and all the other places you have done this "feel weird"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I think the default-features = true should be implicit in this case, so we should be able to omit it.

Copy link
Contributor

@koute koute Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I think it makes sense to do default-features = false in the workspace Cargo.toml on a case-by-case basis if we actually don't want to always enable all of the features for a given dependency, but this probably shouldn't be done by default (at least not blindly), and if you're adding a default-features = true all over the place then it's most likely the wrong thing to do. (If a crate needs a specific feature it should explicitly say which one, instead of doing default-features = true.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in case of the log it looks like it doesn't even have any default features.

Hm. Then we would need to check on every version update whether some default features were added? I guess that could work since the WASM build should fail when it tries to pull in std.

and if you're adding a default-features = true all over the place then it's most likely the wrong thing to do.

Yes I agree if this is the case in 100% of the occurences (and under the assumption that this would not change in the future). But for a dependency where we sometimes want default-features and sometimes not, then we need to set it to false in the workspace i think.

If a crate needs a specific feature it should explicitly say which one, instead of doing default-features = true

If this is the goal, then i dont think that it is automatable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a fun ❤️

Copy link
Contributor

@jsdw jsdw Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into a similar thing when I tried this; you need to specify default-features = false in the worksapce in order to be able to use default-features on that dependency in the crate's Cargo.toml, else you get a warning like:

warning: ..polkadot-sdk/polkadot/xcm/Cargo.toml: `default-features` is ignored for scale-info, 
since `default-features` was not specified for `workspace.dependencies.scale-info`, this could 
become a hard error in the future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is what @ggwpez linked above.

Copy link
Member Author

@ggwpez ggwpez Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So can we go ahead with this:

  • default-features = false in the root workspace for all crates that have a default feature
  • nothing in the crates if the default-features should be true
  • default-features = false in each crate like before when they should be disabled.

This should make the diff here a bit shorter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that works, lets do this.

@ggwpez
Copy link
Member Author

ggwpez commented Oct 28, 2023

And BTW, the wasm-builder currently not supports workspace deps.

What does this mean? That we cannot use it for the no-std runtime dependencies?
Then i will continue with other deps after this PoC is done.

@ggwpez ggwpez self-assigned this Oct 28, 2023
@bkchr
Copy link
Member

bkchr commented Oct 28, 2023

And BTW, the wasm-builder currently not supports workspace deps.

What does this mean? That we cannot use it for the no-std runtime dependencies? Then i will continue with other deps after this PoC is done.

Anything crate that is using wasm builder will not work right now with a workspace dependency. We just need to add support for this.

@ggwpez ggwpez requested review from a team as code owners January 13, 2024 15:21
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez
Copy link
Member Author

ggwpez commented Feb 2, 2024

Anything crate that is using wasm builder will not work right now with a workspace dependency. We just need to add support for this.

How to do this? I see that all CI checks are green. It should catch that or not @bkchr?

@bkchr
Copy link
Member

bkchr commented Feb 5, 2024

Anything crate that is using wasm builder will not work right now with a workspace dependency. We just need to add support for this.

How to do this? I see that all CI checks are green. It should catch that or not @bkchr?

Thinking again about this, my comment wasn't that correct. As we include the real runtime crate as dependency, it is fetching its deps from its original workspace. So yeah, just continue to merge this pr!

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez requested a review from a team as a code owner February 6, 2024 15:37
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez requested a review from bkchr February 7, 2024 13:39
@ggwpez
Copy link
Member Author

ggwpez commented Feb 9, 2024

@koute i guess you are quite busy, but i settled on this idiomatic pattern now:

  • put default-features = false in the workspace
  • re-enable them per-crate with default-features = true if they were previously enabled and leave them disabled otherwise.

I think this pattern is applicable to every dependency, so we dont have to think much and just use some tool to replace it.

Copy link
Contributor

@koute koute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me, although in this specific case of log all of the default-features are pretty much useless since the crate doesn't actually have any default features in the first place, so it's just noise that will confuse people.

So I would suggest that we just use a bare log = { workspace = true } everywhere.

@ggwpez
Copy link
Member Author

ggwpez commented Feb 12, 2024

Looks mostly good to me, although in this specific case of log all of the default-features are pretty much useless since the crate doesn't actually have any default features in the first place, so it's just noise that will confuse people.

So I would suggest that we just use a bare log = { workspace = true } everywhere.

Yes this could be done for now. But if we ever update log and it gets default features, then we would need to change it again.
And at that point we already lost the information in which crates we would like to enable them, since we removed the annotation.

@ggwpez ggwpez added this pull request to the merge queue Feb 12, 2024
@koute
Copy link
Contributor

koute commented Feb 12, 2024

Yes this could be done for now. But if we ever update log and it gets default features, then we would need to change it again. And at that point we already lost the information in which crates we would like to enable them, since we removed the annotation.

I don't see a problem with this, considering any changes to the default features will have to be semver-compatible anyway.

And the "lost the information in which crates we would like to enable them" is, well, complete nonsense considering we're talking about features which don't exist yet. (: How do you know we want to enable a feature if we don't know what that feature is?

Just because a given crate might enable some kind of a feature by default has nothing to do with whether we want to enable or disable it. And there is also no rule that in the client we should enable all of the features by default and in the runtime disable them. A given feature's value lies in what exactly that feature does, and not in whether it's enabled by default or not.

Merged via the queue into master with commit e80c247 Feb 12, 2024
130 checks passed
@ggwpez ggwpez deleted the oty-lift-deps branch February 12, 2024 11:57
@ggwpez
Copy link
Member Author

ggwpez commented Feb 12, 2024

I don't see a problem with this, considering any changes to the default features will have to be semver-compatible anyway.

Oh right. So it should not make a difference anyway until there is a major bump 🙃

And the "lost the information in which crates we would like to enable them" is, well, complete nonsense considering we're talking about features which don't exist yet. (: How do you know we want to enable a feature if we don't know what that feature is?
Just because a given crate might enable some kind of a feature by default has nothing to do with whether we want to enable or disable it. And there is also no rule that in the client we should enable all of the features by default and in the runtime disable them. A given feature's value lies in what exactly that feature does, and not in whether it's enabled by default or not.

Yea true. I only thought about our convention of treating default-features like std.
For the sake of this MR i think its still fine to do, since it only transforms the existing code into a more readable format, without making assumptions about whether that code is correct or not (garbage in = garbage out).
Something that i plan to repeat for more dependencies.

@ggwpez
Copy link
Member Author

ggwpez commented Feb 16, 2024

I changed the default logic now to not write default-features = false if they are enabled everywhere.
This resulted in a more readable diff here: #3366

bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
Changes (partial paritytech#994):
- Set log to `0.4.20` everywhere
- Lift `log` to the workspace

Starting with a simpler one after seeing
paritytech#2065 from @jsdw.
This sets the `default-features` to `false` in the root and then
overwrites that in each create to its original value. This is necessary
since otherwise the `default` features are additive and its impossible
to disable them in the crate again once they are enabled in the
workspace.

I am using a tool to do this, so its mostly a test to see that it works
as expected.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants